package com.zmzncs.lmtc.module.customer.controller;


import com.zmzncs.lmtc.common.pojo.AuthorizeVO;
import com.zmzncs.lmtc.common.pojo.Rest;
import com.zmzncs.lmtc.common.pojo.enums.WhetherEnum;
import com.zmzncs.lmtc.common.util.DateTimeUtil;
import com.zmzncs.lmtc.common.util.JsonUtil;
import com.zmzncs.lmtc.common.util.RestUtil;
import com.zmzncs.lmtc.module.customer.pojo.card.CardDTO;
import com.zmzncs.lmtc.module.customer.pojo.card.CardTimeVO;
import com.zmzncs.lmtc.module.customer.pojo.customer.*;
import com.zmzncs.lmtc.module.customer.service.CustomerService;
import io.swagger.annotations.*;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 客户-客户信息 前端控制器
 * </p>
 *
 * @author 任建波
 * @since 2020-08-26
 */
@Api(tags = "客户信息")
@RestController
@RequestMapping("/customer/info")
public class CustomerController {

    @Autowired
    CustomerService customerService;


    @ApiOperation(value = "微信授权")
    @PostMapping(value = "/authorize")
    public Rest<AuthorizeVO> authorize(@Validated CustomerForm customerForm) {
        AuthorizeVO authorizeVO = customerService.authorize(customerForm);

        return RestUtil.success(authorizeVO);
    }

    @ApiOperation(value = "会员详情")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
    })
    @GetMapping(value = "/getCustomerInfo")
    public Rest<CustomerInfoVO> getCustomerInfo() {
        CustomerDTO customerDTO = customerService.getCustomerInfo();
        CustomerInfoVO customerInfoVO = new CustomerInfoVO();
        BeanUtils.copyProperties(customerDTO, customerInfoVO);
        return RestUtil.success(customerInfoVO);
    }

    @ApiOperation(value = "获取客户月租服务")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
    })
    @GetMapping(value = "/getCustomerMonthCardList")
    public Rest<List<MonthCardVO>> getCustomerMonthCardList() {
        List<CardDTO> cardDTOList = customerService.getCustomerMonthCardList();

        List<MonthCardVO> monthCardVOList = JsonUtil.listTransform(cardDTOList, MonthCardVO.class);

        return RestUtil.success(monthCardVOList);
    }

    @ApiOperation(value = "获取客户时长服务")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
    })
    @GetMapping(value = "/getCustomerDurationCard")
    public Rest<List<DurationCardVO>> customerDurationCard() {
        List<CardDTO> cardDTOList = customerService.getCustomerDurationCard();

        List<DurationCardVO> monthCardVOList = JsonUtil.listTransform(cardDTOList, DurationCardVO.class);

        return RestUtil.success(monthCardVOList);
    }

    @ApiOperation(value = "客户授权绑定手机号")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
            @ApiImplicitParam(paramType="query", name = "code", value = "code", required = true),
            @ApiImplicitParam(paramType="query", name = "encryptedData", value = "encryptedData", required = true),
            @ApiImplicitParam(paramType="query", name = "iv", value = "iv", required = true),
    })
    @GetMapping(value = "/bindMobilePhone")
    public Rest<String> bindMobilePhone(String code, String encryptedData, String iv){
        String phoneNumber = customerService.bindMobilePhone(code, encryptedData, iv);
        return RestUtil.success(phoneNumber);
    }

    @ApiOperation(value = "向用户转账")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
            @ApiImplicitParam(paramType="query", name = "orderCode", value = "订单编号", required = true),
            @ApiImplicitParam(paramType="query", name = "openid", value = "用户openid", required = true),
            @ApiImplicitParam(paramType="query", name = "totalFee", value = "转账总金额", required = true),
            @ApiImplicitParam(paramType="query", name = "desc", value = "转账说明", required = true),
    })
    @PostMapping(value = "/transfers-to-user")
    public Rest<String> transfersToUser(String orderCode,String openid, BigDecimal totalFee, String desc){
        String str = customerService.transfersToUser(orderCode,openid,totalFee,desc);
        return RestUtil.success(str);
    }

}

